﻿using System.Collections;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAssist.Collections;
//using System.Collections;

namespace NetAssistTests
{
  [TestClass()]
  public class UniqueStackTests
  {
    [TestMethod()]
    public void UniqueStackConstructorsTest()
    {
      UniqueStack<int> us1 = new UniqueStack<int>();
      us1.Push(1);
      us1.Push(2);
      us1.Push(3);

      UniqueStack<int> us2 = new UniqueStack<int>(us1);
      UniqueStack<int> us3 = new UniqueStack<int>(10);

      while (us1.Count != 0)
        Assert.IsTrue(us1.Pop() == us2.Pop());

      Assert.IsTrue(us1.Count == 0);
      Assert.IsTrue(us2.Count == 0);
    }

    [TestMethod()]
    public void UniqueStackAccessTest()
    {
      UniqueStack<int> us1 = new UniqueStack<int>(1000);
      us1.Push(1);
      us1.Push(2);
      us1.Push(3);
      us1.Push(1);

      us1.TrimExcess();
      Assert.IsTrue(us1.Count == 3);

      int[] arr = new int[] { 2, 3, 1 };
      int[] arr1;
      int[] arr2 = new int[3];
      object[] arr3 = new object[3];

      arr1 = us1.ToArray();
      us1.CopyTo(arr2, 0);
      us1.CopyTo(arr3, 0);

      for (int i = 0; i < 3; i++)
        Assert.IsTrue(arr[i] == arr1[i] && arr[i] == arr2[i] && arr[i] == (int)arr3[i]);

      Assert.IsTrue(us1.Peek() == 1);
      Assert.IsTrue(us1.Contains(3));

      us1.Clear();
      Assert.IsTrue(us1.Count == 0);
    }

    [TestMethod()]
    public void UniqueStackMiscTest()
    {
      UniqueStack<int> us1 = new UniqueStack<int>();
      us1.Push(1);
      us1.Push(2);
      us1.Push(3);

      Assert.IsTrue(us1.IsSynchronized == false);
      Assert.IsTrue(us1.SyncRoot == us1);

      Stack<int> q1 = us1;

      while (q1.Count != 0)
        Assert.IsTrue(us1.Pop() == q1.Pop());

      Assert.IsTrue(us1.Count == 0);
      Assert.IsTrue(q1.Count == 0);

      int idx = 0;
      foreach (var item in (IEnumerable)us1)
      {
        idx++;
        Assert.IsTrue((int)item == idx);
      }
    }
  }
}
